import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

/// * My Selector
/// * 对[Selector]进行的简单封装
class Ms<A, S> extends Selector0<S> {
  Ms({
    Key? key,
    ShouldRebuild<S>? shouldRebuild,
    required S Function(A) selector,
    required Widget Function(S) builder,
  }) : super(
          key: key,
          builder: (_, S s, __) => builder(s),
          selector: (BuildContext ctx) => selector(Provider.of(ctx)),
          shouldRebuild: shouldRebuild,
        );

  /// 带[child]的[Selector]
  Ms.child({
    Key? key,
    required S Function(A) selector,
    required Widget child,
    required Widget Function(S, Widget) builder,
    ShouldRebuild<S>? shouldRebuild,
  }) : super(
          key: key,
          child: child,
          builder: (_, S s, Widget? c) => builder(s, c!),
          selector: (BuildContext ctx) => selector(Provider.of(ctx)),
          shouldRebuild: shouldRebuild,
        );
}
